/********************************************************************
* Copyright (c) 2012,TGS,All rights reserved.
* fileName:	MeasureTool.h	
* created:	2013/10/10 13:15

* version:	1.6
*********************************************************************/

#pragma once

#include "Maptool.h"

namespace TGS{
namespace MapControl{


class MapCanvas;
class MeasureDialog;
class RubberBand;

class MeasureTool : public MapTool
{
    Q_OBJECT

public:

    MeasureTool(MapCanvas* canvas, bool measureArea );

    ~MeasureTool();
public:
    //! returns whether measuring distance or area
    bool measureArea() const { return _measureArea; }

    //! When we have added our last point, and not following
    // Added in 2.0
    bool done() const { return _done; }

    //! Reset and start new
    void restart();

    //! Add new point
    void addPoint( const Point &point );

    //! Returns reference to array of the points
    const QList<Point>& points();

    // Inherited from QgsMapTool

    //! Mouse move event for overriding
    virtual void canvasMoveEvent( QMouseEvent * e );

    //! Mouse press event for overriding
    virtual void canvasPressEvent( QMouseEvent * e );

    //! Mouse release event for overriding
    virtual void canvasReleaseEvent( QMouseEvent * e );

	virtual void canvasDoubleClickEvent( QMouseEvent * e );

    //! called when set as currently active map tool
    virtual void activate();

    //! called when map tool is being deactivated
    virtual void deactivate();

public slots:
    //! updates the projections we're using
    void updateSettings();
private:
	//! Returns the snapped (map) coordinate
	//@param p (pixel) coordinate
	Point snapPoint( const QPoint& p );
private:
    QList<Point> _points;

    MeasureDialog* _measureDialog;

    //! Rubberband widget tracking the lines being drawn
    RubberBand *_rubberBand;

    //! indicates whether we're measuring distances or areas
    bool _measureArea;

    //! indicates whether we've just done a right mouse click
    bool _done;
};


}//MapControl
}//TGS
